﻿Imports FinanceiroBLL
Imports FinanceiroDAL.ModuloConexao
Public Class RelContasPagar
#Region "RBaberto"
    Private Sub RBAbertos_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBAbertos.CheckedChanged
        If RBAbertos.Checked Then
            gerarelatrio("Contas a Pagar - Parcelas em aberto", "{vw_FinContasPagar.sta_codigo}=4")
        End If
    End Sub
#End Region
#Region "Relatorio"
    Public Sub gerarelatrio(titulo As String, formula As String)
        Try
            Dim frmctasreceber As New RelatoriosfinFRM
            Dim rpt As New ContasPagarREL
            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, titulo)
                rpt.RecordSelectionFormula = formula
                frmctasreceber.CrystalReportViewer2.ShowGroupTreeButton = False
                frmctasreceber.CrystalReportViewer2.ReportSource = rpt
                frmctasreceber.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frmctasreceber.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally

        End Try
    End Sub
#End Region
#Region "Carrega"
    Sub carregarb()
        RBAbertos.Checked = False
        RbAtrasados.Checked = False
        RBFavorecido.Checked = False
        RBPagos.Checked = False
        RBPagosDia.Checked = False
        RBPeriodo.Checked = False
        RBTodas.Checked = False
    End Sub
#End Region
#Region "OK"
    Private Sub BOK_Click(sender As System.Object, e As System.EventArgs) Handles BOK.Click
        If RBPeriodo.Checked = True Then
            Dim opt As Integer = 0
            opt = DateTime.Compare(dtinicio.Value, dtfim.Value)
            If opt <= 0 Then
                gerarelatrio("Parcelas pagas- Período:" & dtinicio.Value.Date & " até " & dtfim.Value.Date, "{vw_FinContasPagar.sta_codigo} =6 and {vw_FinContasPagar.ccc_codigo} > 0  and {vw_FinContasPagar.icp_datapagamento} >='" & dtinicio.Value.ToString("yyyy-MM-dd") & "' and {vw_FinContasPagar.icp_datapagamento} <= '" & dtfim.Value.ToString("yyyy-MM-dd") & "'")
            End If
        End If
    End Sub
#End Region
#Region "BTNok"
    Private Sub BTNok_Click(sender As System.Object, e As System.EventArgs) Handles BTNok.Click
        If RBFavorecido.Checked Then
            If txtNome.Text <> "" Then
                gerarelatrio("Partcelas por Favorecidos - Contas a Pagar", "{vw_FinContasPagar.sta_codigo}=4  And {vw_FinContasPagar.ctp_fornprestador} ='" & (txtNome.Text) & "'")
                txtNome.Text = ""
            End If
        End If
    End Sub
#End Region
#Region "RBpagos"
    Private Sub RBPagos_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBPagos.CheckedChanged
        If RBPagos.Checked Then
            gerarelatrio("Contas a Pagar - Parcelas pagas", "{vw_FinContasPagar.sta_codigo}=6")
        End If
    End Sub
#End Region
#Region "RbAtrasados"
    Private Sub RbAtrasados_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RbAtrasados.CheckedChanged
        If RbAtrasados.Checked Then
            gerarelatrio("Contas a Pagar - Parcelas atrasadas", "{vw_FinContasPagar.sta_codigo}=4 and {vw_FinContasPagar.icp_datavencimento} < '" & Date.Now.ToString("yyyy-MM-dd") & "'")
        End If
    End Sub
#End Region
#Region "Rbpagos"
    Private Sub RBPagosDia_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBPagosDia.CheckedChanged
        If RBPagosDia.Checked Then
            gerarelatrio("Contas a Pagar - Pagamentos do Dia", "{vw_FinContasPagar.sta_codigo}=6 and {vw_FinContasPagar.icr_datapagamento}='" & Date.Now.ToString("yyyy-MM-dd") & "'")
        End If
    End Sub
#End Region
#Region "RBPeriodo"
    Private Sub RBPeriodo_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBPeriodo.CheckedChanged
        If RBPeriodo.Checked = True Then
            gbPeriodo.Enabled = True
        End If
    End Sub
#End Region
#Region "Localiza"
    Private Sub BLocaliza_Click(sender As System.Object, e As System.EventArgs) Handles BLocaliza.Click
        Dim frm As New PessoaCON
        frm.type = "ret"
        frm.ShowDialog()
        txtNome.Text = frm.fornprest
        frm.Dispose()
        frm = Nothing
        ' txtNome.Text = ""
    End Sub
#End Region
#Region "RBTodas"
    Private Sub RBTodas_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBTodas.CheckedChanged
        If (RBTodas.Checked) Then
            gerarelatrio("Contas a Pagar - Todas as parcelas", "")
        End If
    End Sub
#End Region
#Region "RBFavorecido"
    Private Sub RBFavorecido_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBFavorecido.CheckedChanged
        If RBFavorecido.Checked = True Then
            GBFavorecido.Enabled = True
        End If
    End Sub
#End Region
End Class